<include file="Public/min-header"/>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
<style> 
	  #fenlei_box{border: 1px solid #3297ff;position: absolute;width:450px;height:250px;overflow:hidden; z-index:9999;background:#fff;display:none;}
	  #fenlei_box li{list-style: none;color:#3297ff;text-align:left;margin-left:-20px;line-height: 32px;cursor: pointer;border-bottom:1px dashed}#teshu,#z_jine{color:red;}
</style>
    <section class="content">
        <!-- Main content -->
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 修改订单信息 
                    <if condition="$order.coupon_id neq 0"><span style="color:red;font-weight:910;">此单用户使用了优惠券，修改订单会使优惠券失效</span></if>
                    </h3>
                </div>
                <div class="panel-body">
                    <!--表单数据-->
                    <form method="post" action="{:U('Order/edit_order')}" id="order-add">
                        <div class="tab-pane">
                            <table class="table table-bordered">
                                <tbody>
								<tr>
								    <td width="110">下单类型:</td>
                                    <td>
                                        <?php if($order['dai_type']=='2')
									{
									?>
                                        <label><input name="dai_type" id="dai_type" type="radio" checked="checked" value="2" style="margin-left:10px;"/> 特殊线下单</label><span style="color: red;">(线下私有客户)</span>


                                        <?php
									   }else{
									   ?>
                                        <label><input name="dai_type" id="dai_type" type="radio" checked="checked" value="{$order['dai_type']}"/> 普通线上单</label>
                                        <?php
									   }
									   ?>
                                    </td>
								</tr>
								<tr style="color:#3c8dbc;"><td>单号:</td>
									<td>
										<div class="col-xs-9">
										{$order.order_sn}
										</div></td>
								</tr>
                                <tr><td>费用信息:</td>
                                	<td>
                                		<div class="col-xs-9">
                                		<input type="hidden" name="order_id" value="{$order.order_id}">
                                		订单总额：{$order.total_amount} = 商品总价：{$order.goods_price}+运费:{$order.shipping_price}
                                		</div></td>
                                </tr>
                                <tr>
                                    <td>客户公司名:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-2">
											<input name="company" id="company" value="{$order.company}" class="form-control" placeholder="客户公司名" />
                                        </div>  
                                    </div>    
                                    </td>
                                </tr>
                                <tr>
                                    <td>收货人:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-2">
	                                        <input name="consignee" id="consignee" value="{$order.consignee}" class="form-control" placeholder="收货人名字" />
                                        </div>  
                                        <div class="col-xs-2">
										    <span id="err_consignee" style="color:#F00; display:none;">收货人名字不能为空</span>
                                        </div> 
                                    </div>    
                                    </td>
                                </tr>
                                <tr>
                                     <td>地址:</td>
                                     <td>
                                     <div class="form-group ">
                                         <div class="col-xs-4">
                                         <input name="address" id="address" value="{$order.address}" class="form-control"   placeholder="详细地址" />
                                </div>
                                <div class="col-xs-2">
                                <span id="err_address" style="color:#F00; display:none;">请完善收货地址</span>
                                         </div>
                                	</div>  
                                     </td>
                                 </tr>
                                 <tr style="display: none;">
                                     <td>手机:</td>
                                     <td>
                                     <div class="form-group ">
                                         <div class="col-xs-2">
                                             <input name="mobile" id="mobile" value="{$order.mobile}" class="form-control" placeholder="收货人联系电话" readonly="readonly"/>
                                         </div>
                                <div class="col-xs-2">
                                <span id="err_mobile" style="color:#F00; display:none;">收货人电话不能为空</span>
                                         </div> 
                                     </div>    
                                     </td>
                                 </tr>
								<?php if($order['dai_type']=="2")
								{
									$fujian=empty($order['fujian']) ? '/Public/images/add-button.jpg' :$order['fujian'];
								?>
                                <tr id="teshu">
                                     <td>特殊单金额:</td>
                                     <td>
                                     <div class="form-group "> 
                                         <div class="col-xs-2">
                                             <input name="z_jine" id="z_jine" type="number" value="{$order.total_amount}" class="form-control" placeholder="总金额"/> 
                                         </div><div class="col-xs-2">
                                <span id="err_z_jine" style="color:#F00; display:none;">总金额为空</span>
                                         </div> 
                                     </div>    
                                     </td>
                                 </tr>
								<tr id="teshu" style="color:unset;">
								         <td>特殊附件:</td> 
															<td>
															<div class="goods_xc" style="width:70px; text-align:center; margin: 5px; display:inline-block;">
																<input type="hidden" name="fujian" id="fujian" value="{$order.fujian}">
																<a href="javascript:void(0);" onclick="GetUploadify(1,'','goods','call_back2');">
																	<img src="{$fujian}" width="70" height="70"></a>
																<br>
																<a href="javascript:void(0)">&nbsp;&nbsp;</a>
															</div>  <span style="color:#999;">（选填，可上传实际单据）</span>
															</td>
								     </tr>
								 <?php
								 }
								 ?>
                                 <tr>
                                <tr>
                                    <td>添加商品:</td>
                                    <td>
                                        <div class="form-group">
                                            <div class="col-xs-2">                                        
	                                            <a class="btn btn-primary" href="javascript:void(0);" onclick="selectGoods()" ><i class="fa fa-search"></i>添加商品</a>
                                            </div>                                                            
                                            <div class="col-xs-2">
                                                <span id="err_goods" style="color:#F00; display:none;">请添加下单商品</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>商品列表:</td>
                                    <td> 
                                       <div class="form-group">
                                       		<div class="col-xs-10">
                                       		<table class="table table-bordered">
                                       			<thead>
                                       			<tr>
									                <td class="text-left">商品名称</td>
									                <td class="text-left">规格</td>
									                <td class="text-left">价格</td>
									                <td class="text-left">数量<span style="color:red;font-size:13px;">（支持小数点补差价）</span></td>
									                <td class="text-left">操作</td>
									            </tr>
									            </thead>
									            <tbody>
									            <foreach name="orderGoods" item="vo">
									            	<tr>
									                <td class="text-left">{$vo.goods_name}</td>            
									                <td class="text-left">{$vo.spec_key_name}</td>
									                <td class="text-left">
                                                        <input type="text" class="input-sm" name="old_price[{$vo.rec_id}]" value="{$vo.goods_price}" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                                    </td>
									                <td class="text-left">
									                <input type="hidden" name="spec[]" rel="{$vo.goods_id}" value="{$vo.spec_key}">
									                <input type="text" class="input-sm" name="old_goods[{$vo.rec_id}]" value="{$vo.goods_num}" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"></td>
									                <td class="text-left"><a href="javascript:void(0)" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
									           		</tr>
									           </foreach>
									           </tbody>
                                       		</table>
                                       	   </div>
                                       </div>
                                       <div class="form-group">
                                            <div class="col-xs-10" id="goods_td">
                                                <table class="table table-bordered">
                                                </table>
                                            </div>
	                                   </div>
                                    </td>
                                </tr>
                               <tr>
                                    <td>单据备注:</td>
                                    <td>
                                    <div class="form-group ">
										<div class="col-xs-8">
											<textarea style="width:100%; height:150px;" class="ckeditor" name="user_note" id="user_note">{$order.user_note|htmlspecialchars_decode}</textarea>
											<span id="err_user_note" style="color:#F00; display:none;">特殊单据备注不能为空</span>
										</div>
                                    </div>    
                                    </td>
                                </tr>
                                
                                </tbody>
                                </table>
                        </div>
                        <input type="hidden" name="id" value="{$order.order_id}">
                        <input type="hidden" id="coupon_id" name="coupon_id" value="{$order.coupon_id}">
                        <button class="btn btn-info" type="button" onclick="checkSubmit()">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                          		 保存
                        </button>
                    </form> 
                </div>
            </div>
        </div> 
    </section>
</div>
<!--以下是在线编辑器 代码 -->
<script type="text/javascript">
    /*
	 * 在线编辑器相 关配置 js
	 *  参考 地址 http://fex.baidu.com/ueditor/
	 */
	
    function call_back2(paths){
            $(".goods_xc").find('img').attr('src',paths);// 修改他的图片路径
            $(".goods_xc").find('a:eq(1)').attr('onclick',"ClearPicArr2(this)").text('删除');
            $(".goods_xc").find('#fujian').val('{$myurl}'+paths); // 设置隐藏域 要提交的值
    }
	    function ClearPicArr2(obj)
	    {
	        $(obj).parent().find('img').attr('src','/Public/images/add-button.jpg'); // 删除完服务器的, 再删除 html上的图片
			$(".goods_xc").find('#fujian').val('');
		}
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "https://{:$_SERVER['HTTP_HOST']}{$URL_upload}";
    var URL_fileUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_fileUp}";
    var URL_scrawlUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_scrawlUp}";
    var URL_getRemoteImage = "http://{:$_SERVER['HTTP_HOST']}{$URL_getRemoteImage}";
    var URL_imageManager = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageManager}";
    var URL_imageUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageUp}";
    var URL_getMovie = "http://{:$_SERVER['HTTP_HOST']}{$URL_getMovie}";
    var URL_home = "http://{:$_SERVER['HTTP_HOST']}{$URL_home}";
</script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "95%", //初化宽度
            initialFrameHeight: 300, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign'
            , //允许的最大字符数 'fullscreen',
            pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: true,
        	toolbars: [
                   ['fullscreen', 'source', '|', 'undo', 'redo',
                       '|', 'bold', 'italic', 'underline', 'fontborder',
                       'strikethrough', 'superscript', 'subscript',
                       'removeformat', 'formatmatch', 'autotypeset',
                       'blockquote', 'pasteplain', '|', 'forecolor',
                       'backcolor', 'insertorderedlist',
                       'insertunorderedlist','selectall', 'cleardoc']
               ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("user_note");  //  指定 textarea 的  id 为 goods_content

    });
	
   /* 用户订单区域选择 */
$(document).ready(function(){
	$('#province').val({$order.province});
	$('#city').val({$order.city});
	$('#district').val({$order.district});
	$('#shipping_id').val({$order.shipping_id});
});
// 选择商品
function selectGoods(){
    var url = "{:U('seller/Order/search_goods',['order_id'=>$order['order_id']])}";
    layer.open({
        type: 2,
        title: '选择商品',
        shadeClose: true,
        shade: 0.8,
        area: ['60%', '60%'],
        content: url, 
    });
}

// 选择商品返回
function call_back(table_html)
{
	//$('#goods_td').empty().append('<table class="table table-bordered">'+table_html+'</table>');
	//过滤选择重复商品
	// $('input[name*="spec"]').each(function(i,o){
	// 	if($(o).val()){
	// 		var name='goods_id['+$(o).attr('rel')+']['+$(o).val()+'][goods_num]';
	// 		$('input[name="'+name+'"]').parent().parent().remove();
	// 	}
	// });
	// layer.closeAll('iframe');
	$('#goods_td .table-bordered').append(table_html);console.log(table_html);
	layer.closeAll('iframe');
}

function checkSubmit()
{	
    
//     var coupon_id = $('#coupon_id').val()
//   if(coupon_id > 0){
//       layer.alert('此单用户使用了优惠券，修改订单会使优惠券失效', {icon: 2});
//   }
    
    
	$("span[id^='err_']").each(function(){
		$(this).hide();
	});
	var pd_err=0;
	$("input[name^='old_goods']").each(function(){
		var zhi=$(this).val();
		if(zhi=='' || zhi==0){
			pd_err=1;
			return false;
		}
	});
	$("input[name^='goods_id']").each(function(){
		var zhi=$(this).val();
		if(zhi=='' || zhi==0){
			pd_err=1;
			return false;
		}
	});
	if(pd_err>0){
		layer.alert('产品数量不能为0！', {icon: 2});
		return false;
	}
	
   ($.trim($('#consignee').val()) == '') && $('#err_consignee').show();
   // ($.trim($('#province').val()) == '') && $('#err_address').show();
   // ($.trim($('#city').val()) == '') && $('#err_address').show();
   // ($.trim($('#district').val()) == '') && $('#err_address').show();
   // ($.trim($('#address').val()) == '') && $('#err_address').show();
   //($.trim($('#mobile').val()) == '') && $('#err_mobile').show();						   						   						   	
   if(($("input[name^='goods_id']").length ==0) && ($("input[name^='old_goods']").length == 0)){
	   layer.alert('订单中至少要有一个商品', {icon: 2});  // alert('少年,订单中至少要有一个商品');
	   return false;
   }			
   
   
   if($("span[id^='err_']:visible").length > 0 ) 
      return false;							  
   $('#order-add').submit();	  
}
</script>
</body>
</html>